﻿using System;
using System.Collections.Generic;
using System.Text;
using PPIDesktopClient.General;

namespace PPIDesktopClient.Entities
{
    [Serializable]
    public class EVendor_Visit_XMissionStructure : EBaseAsset
    {
        #region Miembros Privados
        EVendor_Project m_Vendor_Project;
        EUtility_Asset_XMissionStructure m_Utility_Asset_XMissionStructure;
        EVendor_Visit_Type m_Vendor_Visit_Type;
        EVendor_Contact m_Vendor_Contact;
        Int32 m_StructureServerID;
        DateTime m_UploadedDate;
        string m_ConnectionString = "";
        bool m_IsMobile = false;

        #endregion Miembros Privados

        #region Propiedades
        public EVendor_Project Vendor_Project
        {
            get { return m_Vendor_Project; }
            set { m_Vendor_Project = value; }
        }
        public EUtility_Asset_XMissionStructure Utility_Asset_XMissionStructure
        {
            get { return m_Utility_Asset_XMissionStructure; }
            set { m_Utility_Asset_XMissionStructure = value; }
        }
        public EVendor_Visit_Type Vendor_Visit_Type
        {
            get { return m_Vendor_Visit_Type; }
            set { m_Vendor_Visit_Type = value; }
        }
        public EVendor_Contact Vendor_Contact
        {
            get { return m_Vendor_Contact; }
            set { m_Vendor_Contact = value; }
        }

        public Int32 StructureServerID
        {
            get { return m_StructureServerID; }
            set { m_StructureServerID = value; }
        }
        public DateTime UploadedDate
        {
            get { return m_UploadedDate; }
            set { m_UploadedDate = value; }
        }
        public string ConnectionString
        {
            get { return m_ConnectionString; }
            set { m_ConnectionString = value; }
        }
        public bool IsMobile
        {
            get { return m_IsMobile; }
            set { m_IsMobile = value; }
        }

        public string ProjectTitle
        {
            get
            {
                if (Vendor_Project.Vendor_ProjectId != Int32.MinValue)
                {
                    return Vendor_Project.Name;

                }
                else
                {
                    return "No project assigned";
                }
            }
        }

        public string VendorContact
        {
            get 
            {
                if (Vendor_Contact.Vendor_ContactId != Int32.MinValue)
                {
                    return Vendor_Contact.Name;
                }
                else
                {
                    return "No Contact";
                }
            }
        }

        public string AssetTypeTitle
        {
            get 
            {
                if (Vendor_Visit_Type.Vendor_Visit_TypeId != Int32.MinValue)
                {
                    return Vendor_Visit_Type.Name;
                }
                else
                {
                    return "No Type";
                }
            }
        }

        #endregion Propiedades

        #region Constructores
        #region summary
        /// <summary>
        /// Date: 04/28/2008
        /// Time: 11:48:18
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public EVendor_Visit_XMissionStructure()
        :base()
        {
            m_ListPolesDelete = new List<Int32>();
            m_ListImagesDelete = new List<Int32>();
            m_Vendor_Contact = new EVendor_Contact();
            m_Vendor_Visit_Type = new EVendor_Visit_Type();
            m_Utility_Asset_XMissionStructure = new EUtility_Asset_XMissionStructure();
            m_Vendor_Project = new EVendor_Project();

        }

        #region summary
        /// <summary>
        /// Date: 04/28/2008
        /// Time: 11:48:18
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public EVendor_Visit_XMissionStructure(Int32 vendor_Visit_XMissionStructureId)
            : this()
        {
            Id = vendor_Visit_XMissionStructureId;

        }

        #region summary
        /// <summary>
        /// Date: 04/28/2008
        /// Time: 11:48:18
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public EVendor_Visit_XMissionStructure(Int32 vendor_Visit_XMissionStructureId, EVendor_Project vendor_Project, EUtility_Asset_XMissionStructure utility_Asset_XMissionStructure, EVendor_Visit_Type vendor_Visit_Type, EXMissionStructures_TopType xMissionStructures_TopType, double latitude, double longitude, double altitude, Int32 satelliteCount, DateTime satelliteTime, bool solutionAvailable, string handheld, EVendor_Contact vendor_Contact, DateTime date)
            : this(vendor_Visit_XMissionStructureId)
        {
            m_Vendor_Project = vendor_Project;
            m_Utility_Asset_XMissionStructure = utility_Asset_XMissionStructure;
            m_Vendor_Visit_Type = vendor_Visit_Type;
            TopType = xMissionStructures_TopType;
            Latitude  = latitude;
            Longitude  = longitude;
            Altitude = altitude;
            SatelliteCount = satelliteCount;
            SatelliteTime = satelliteTime;
            SolutionAvailable = solutionAvailable;
            Handheld.Name = handheld;
            m_Vendor_Contact = vendor_Contact;
            Date = date;

        }

        #endregion Constructores

        #region Public Methods

        public int CalculateTotalImages()
        {
            return Images.Count;
        }

        public void DeletePole(int poleID)
        {
            m_ListPolesDelete.Add(poleID);
        }

        public void DeleteImage(int ImageID)
        {
            m_ListImagesDelete.Add(ImageID);
        }
        #endregion

        #region Override Methods

        public override string GetHtmlDescription()
        {
            StringBuilder _Shtml = new StringBuilder();
            _Shtml.AppendLine("<table style='font-family:Verdana; font-size:10px;' border='0'>");
            //Header
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td colspan=\"" + Poles.Count + 1 + "\"><b>XMission Structure | GPS Visit [" + Id + "]</b></td>");
            _Shtml.AppendLine(" </tr>");
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td colspan=\"" + Poles.Count + 1 + "\" >");
            _Shtml.AppendLine("         <table>");
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td>Visitor: " + m_Vendor_Contact.Name + " of " + m_Vendor_Project.Vendor.Name + "</td>");
            _Shtml.AppendLine("             </tr>");
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td>Date : " + SatelliteTime.ToString("m") + ", " + SatelliteTime.ToString("yyyy") + " at " + SatelliteTime.ToString("HH:mm tt") + "</td>");
            _Shtml.AppendLine("             </tr>");
            _Shtml.AppendLine("         </table>");
            _Shtml.AppendLine("     </td>");
            _Shtml.AppendLine(" </tr>");

            //Content
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td>");
            _Shtml.AppendLine("         <table border='0'>");
            foreach (EBaseImage i in Images)
            {
                if (i.Pole.Id == Int32.MinValue)
                {
                    _Shtml.AppendLine("         <tr>");
                    _Shtml.AppendLine(i.GetHtml());
                    _Shtml.AppendLine("         </tr>");
                }
            }
            _Shtml.AppendLine("         </table>");
            _Shtml.AppendLine("     </td>");

            foreach (EBasePole p in Poles)
            {
                _Shtml.AppendLine("     <td>");
                _Shtml.AppendLine(p.GetHtmlDescription());
                _Shtml.AppendLine("     </td>");
            }
            _Shtml.AppendLine(" </tr>");
            string _webAdrress = Constants.K_GoogleMapDirectionsWEB;
            _webAdrress = _webAdrress.Replace("KML_DEST_ADDRESS", GetAddress());
            _webAdrress = _webAdrress.Replace("KML_SOURCE_ADDRESS", "100 Main Street Ovid, CO  80744".Replace(" ", "+"));
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td colspan=\"" + Poles.Count + 1 + "\">");
            _Shtml.AppendLine("         <table bolder='0'>");
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td><a href=\"" + _webAdrress + "\">Get directions from Ovid office</a></td>");
            _Shtml.AppendLine("             </tr>");
            _webAdrress = Constants.K_GoogleMapDirectionsWEB;
            _webAdrress = _webAdrress.Replace("KML_DEST_ADDRESS", GetAddress());
            _webAdrress = _webAdrress.Replace("KML_SOURCE_ADDRESS", "16107 Hwy 14 Sterling, CO  80751".Replace(" ", "+"));
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td><a href=\"" + _webAdrress + "\">Get directions from Sterling office</a></td>");
            _Shtml.AppendLine("             </tr>");
            _webAdrress = Constants.K_GoogleMapDirectionsWEB;
            _webAdrress = _webAdrress.Replace("KML_DEST_ADDRESS", GetAddress());
            _webAdrress = _webAdrress.Replace("KML_SOURCE_ADDRESS", "1300 S Interocean Holyoke, CO  80734".Replace(" ", "+"));
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td><a href=\"" + _webAdrress + "\">Get directions from Holyoke office</a></td>");
            _Shtml.AppendLine("             </tr>");
            _Shtml.AppendLine("         </table>");
            _Shtml.AppendLine("     </td>");
            _Shtml.AppendLine("</table>");
            return _Shtml.ToString();
        }

        protected override string GetPlacemarkId()
        {
            return "Vendor_" + Id.ToString();
        }

        #endregion
    }
}

